package Euler17;

import ReusableCode.MathFunctions;

public class NumberLetters {
	public static void main(String[] args) {
		long sum = 0;
		String numbers[] = new String[10001];
		
		//Set numbers.
		numbers[1] = "one";
		numbers[2] = "two";
		numbers[3] = "three";
		numbers[4] = "four";
		numbers[5] = "five";
		numbers[6] = "six";
		numbers[7] = "seven";
		numbers[8] = "eight";
		numbers[9] = "nine";
		numbers[10] = "ten";
		numbers[11] = "eleven";
		numbers[12] = "twelve";
		numbers[13] = "thirteen";
		numbers[14] = "fourteen";
		numbers[15] = "fifteen";
		numbers[16] = "sixteen";
		numbers[17] = "seventeen";
		numbers[18] = "eighteen";
		numbers[19] = "nineteen";
		numbers[20] = "twenty";
		numbers[30] = "thirty";
		numbers[40] = "forty";
		numbers[50] = "fifty";
		numbers[60] = "sixty";
		numbers[70] = "seventy";
		numbers[80] = "eighty";
		numbers[90] = "ninety";
		numbers[1000] = "onethousand";
		
		for(int i = 1; i <= 1000; i++)
		{
			String number = "";
			if((i<100) || (i == 1000))
			{
				number = getNumberString(i, numbers);
			}
			else
			{
				int count[] = MathFunctions.getDigits(i);
				int sub = (count[1]*10) + count[0]; 
				number = numbers[count[2]] + "hundred";
				
				//System.out.println(count[0] + "   " + count[1] + "    " + count[2]);
				
				if(sub!=0)
				{
					number += "and" + getNumberString(sub, numbers);
				}
			}
			
			sum += number.length();
			System.out.println(number + ":   " + number.length());
		}
		
		System.out.println(sum);
	}
	
	static String getNumberString(int i, String numbers[])
	{
		String number = "";
		if((i<20) || (i == 1000))
		{
			number = numbers[i];
		}
		else if(i < 100)
		{
			int count = MathFunctions.getDigit(i, 1);
			if (count!=0)
			{
				number = numbers[i-count] + numbers[count];
			}
			else
			{
				number = numbers[i];
			}
		}
		
		return number;
	}
}
